/**
 * 
 */
package com.sl;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.annotation.AsyncConfigurerSupport;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @author lunshi
 *
 */
@SpringBootApplication
@EnableAsync
public class AsyncApp extends AsyncConfigurerSupport{

	public static void main(String[] args) {
		SpringApplication.run(AsyncApp.class, args);
	}
	
	@Override
	public Executor getAsyncExecutor() {
		ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
		executor.setCorePoolSize(3);
		executor.setMaxPoolSize(5);
		executor.setQueueCapacity(100);
		executor.setThreadNamePrefix("CustomTaskExcutor--");
		return executor;
	}
	
	//@Bean
	public AsyncTaskExecutor asyncTaskExecutor() {
	    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
	    executor.setThreadNamePrefix("CustomTaskExcutor-");
	    executor.setMaxPoolSize(10);
	    executor.setCorePoolSize(3);
	    executor.setQueueCapacity(0);
	    executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
	    return executor;
	}
}
